<?php
namespace app\lmsx\model;

use think\Model;
use traits\model\SoftDelete;
use think\Db;

/**
 * 识别码模型
 * @author lan
 */
class Code extends Model
{
    use SoftDelete;
    protected $table = 'dp_lmsx_code';
    protected $autoWriteTimestamp = true;

    /**
     * 生成唯一识别码，每个用户识别码唯一
     */
    public function createCode(){
        while (true){
            $str=mt_rand(100000,999999);
            $row=Db::table('dp_lmsx_code')->where(['code'=>$str])->find();
            if (empty($row)) {
                break;
            }
        }
        return $str;
    }

    /**
     * 获取所有的用户
     */
    public function getAllUser(){
        $list=Db::table('dp_lmsx_user')->order('id desc')->column('id,nickname');
        if(empty($list)){
            $list[0]='暂无用户';
        }
        return $list;
    }
}
